Python |
您所在的位置:网站首页 › turtle 打字 › Python |
目录 一、设置画布 二、画笔 1、画笔属性 2、绘图命令 (1) 画笔运动命令 (2) 画笔控制命令 (3) 全局控制命令 (4) 其他命令 3. 命令详解 三、文字显示为一个圆圈 四、画朵小花 一、设置画布turtle为我们展开用于绘图区域,我们可以设置它的大小和初始位置 turtle.screensize(canvwidth=600,canvheight=800,bg='black')#参数分别代表画布的宽、高、背景色turtle.screensize()#返回默认大小(400,300) turtle.setup(width=0.6,height=0.6,startx=100,starty=100)#输入宽和高为整数时, 表示像素; 为小数时, 表示占据电脑屏幕的比例#(startx, starty): 这一坐标表示矩形窗口左上角顶点的位置, 如果为空,则窗口位于屏幕中心 二、画笔 1、画笔属性turtle.pensize(8) #画笔粗细 turtle.color('red') #画笔颜色 字符串"green", "red" 或者 RGB 3元组。 turtle.speed(0) #画笔移动速度 画笔绘制的速度范围[0,10]整数,数字越大越快 2、绘图命令 (1) 画笔运动命令turtle.forward(8) #向前移动 turtle.backward(8) #向后移动 turtle.right(90) #海龟方向向右转90° turtle.left(90) #海龟方向向左转90° turtle.penup() #提笔 turtle.pendown() #落笔 turtle.goto(x,y) 海龟移动到(x,y)位置 turtle.setx(x) 海龟的x坐标移动到指定位置 turtle.sety(y) 海龟的y坐标移动到指定位置 turtle.circle() 画圆 turtle.dot() 画一个圆点(实心) turtle.setheading(angle) #设置当前朝向为angle角度 turtle.home() 设置当前画笔位置为原点,朝向东(默认值) (2) 画笔控制命令turtle.fillcolor('red') 设置 填充颜色 turtle.color(color1, color2) 设置 画笔颜色为color1,填充颜色为color2 turtle.begin_fill() 开始填充颜色 turtle.end_fill() 填充完成 turtle.hideturtle() 隐藏海龟图标 turtle.showturtle() 显示海龟图标 (3) 全局控制命令turtle.clear() 清空turtle窗口,但是turtle的位置和状态不会改变 turtle.reset() 清空turtle窗口,重置turtle状态为起始状态 turtle.undo() 撤销上一个turtle动作 turtle.isvisible() 返回当前turtle是否可见 t.write("文本" ,align="center",font=("微软雅黑",20,"normal")) 写文本 align(可选):left,right,center;font(可选):字体名称,字体大小,字体类型(normal,bold,italic) (4) 其他命令参数: radius(半径):半径为正(负),表示圆心在画笔的左边(右边)画圆; extent(弧度) ; steps :(做半径为radius的圆的内切正多边形,多边形边数为steps)。 import turtle as t t.circle(50)#整圆 t.circle(50,steps=3)#内置的三角形 t.penup() t.goto(100,0) t.pendown() t.circle(50,180)#半圆参考原文链接:https://blog.csdn.net/zengxiantao1994/article/details/76588580 三、文字显示为一个圆圈 import turtle as t text="棉花娃娃很可爱" t.penup() x=len(text) for i in text: t.write(i,font='consolas') t.right(360/x) t.penup() t.forward(30) t.hideturtle() |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |